// 这是我store的代码
import { Commit } from 'vuex'
// 引入 store.d.ts 下定义的 LoginState

import { LoginState } from '@/types/store'
export interface IUser {
  email: string
  token: string
  username: string
  bio: string
  image: string
}

// 引入全局的
const state: LoginState = {
  user: {}
}

const mutations = {
  setUser(state: LoginState, user: IUser) {
    state.user = user
  }
}

const actions = {
  setUser(context: { state: LoginState, commit: Commit }, user: IUser) {
    context.commit('setUser', user)
  }
}

export default {
  // namespaced为false的时候，state,mutations,actions全局可以调用，为true，生成作用域，引用时要声明模块名称
  namespaced: true,
  state,
  mutations,
  actions
}
